#ifndef PYSCRIPT_H
#define PYSCRIPT_H
#include <QtWidgets>
#include "Python.h"

class PPScriptExec{

public:

    enum ImageVariantType{
        ExtendX,
        ExtendY,
        ExtendA,

    };

    ~PPScriptExec(){
        PyGC_Collect();
    }

    static std::pair<QStringList, QMap<QString, QStringList>> PyScript_WingsGet(const char *_module,
                                                                                                                          const char *ModulePath,
                                                                                                                          const char *_func,
                                                                                                                          QStringList Columns);

    static void PyScript_MediainfoGet(const char *_module,
                                      const char *_func,
                                      const char *MediaPath,
                                      QMap<QString, QString> &get);

    static QString PyScript_UnitTchz(const char *_module,
                                     const char *_func,
                                     const char *string,
                                     QString &get);

    static bool PyScript_AssertReply(const char *_module,
                                     const char *_func,
                                     const char *RequestPath,
                                     QMap<QString, QString> &RequestHead);

    static void pyScript_ImageByteDressMaker(const char *_module,
                                             const char *_func,
                                             const char *_file,
                                             QList<qint64> &clipsize_send,
                                             QList<qint64> &clipping_send,
                                             QString &bytestr);

    static void pyScript_PilrsizeforPixmap(const char *model,
                                           const char *_func,
                                           QPixmap &pixmap,
                                           QList<int> size);

    static void pyScript_QrcodeByte(const char *_module,
                                    const char *_func,
                                    const char *_qrdata,
                                    QPixmap &pixmap,
                                    const char *_savePath=NULL,
                                    const char *_fore="red",
                                    const char *_back="white",
                                    uint _borderxp=5,
                                    uint _sizertxp=5);

    static void pyScript_PixmapVariant(QSize expsize,
                                       QPixmap &pixmap,
                                       QSize fsize,
                                       bool hiq=false,
                                       QVariant curtain="");

    static bool pyScript_PixmapVariant(QPixmap &pixmap,
                                       QVariant curtain);

    static bool pyScript_PixmapVariant(QVariant curtain);

private:

    QString scriptFolder = QCoreApplication::applicationDirPath();
    static QStringList &PyScript_ExtraToststr(QStringList &mangList, PyObject *resource);

    PPScriptExec(){
        if (!Py_IsInitialized()){
            Py_Initialize();
            if (Py_IsInitialized())
            {
                std::string importhome = QString("sys.path.append('%1')").arg(scriptFolder).toStdString();
                PyRun_SimpleString("import sys");
                PyRun_SimpleString(importhome.data());
                qDebug() << "成功初始化python解释器";
            }
        }
    };

    static const char* PyScript_ExtraTostr(PyObject *resource);

    static bool PyScript_ExtraTobool(PyObject *resource);

    static PyObject* PyScript_CreateTodict(QMap<QString, QString> &Map);

    static QStringList PyScript_ExtraAnststr(PyObject *resource);

    static std::pair<QStringList, QMap<QString, QStringList>> PyScript_ExtraAnststrm(PyObject *resource);

    static std::pair<QStringList, QMap<QString, QString>> PyScript_ExtraTostrm(PyObject *resource);

};


#endif // PYSCRIPT_H
